package com.glodon.paas.document.dao.mysql;

import org.springframework.beans.factory.annotation.Autowired;

import com.glodon.paas.document.dao.PublicTokenDao;
import com.glodon.paas.document.dao.domain.PublicTokenEntity;
import com.glodon.paas.document.dao.mapper.PublicTokenMapper;

public class PublicTokenDaoMysqlImpl implements PublicTokenDao {

    @Autowired
    PublicTokenMapper publicTokenMapper;

    @Override
    public String insert(PublicTokenEntity entity) {
        if (publicTokenMapper.insert(entity) > 0) {
            return entity.getFileId();
        } else {
            return null;
        }
    }

    @Override
    public PublicTokenEntity get(String id) {
        return publicTokenMapper.selectByPrimaryKey(id);
    }

    @Override
    public int delete(String id) {
        return publicTokenMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(PublicTokenEntity entity) {
        return publicTokenMapper.updateByPrimaryKey(entity);
    }

    @Override
    public PublicTokenEntity getByToken(String token) {
        return publicTokenMapper.selectByToken(token);
    }

}
